﻿using System;
using System.Collections.Generic;
using System.Text;
using LabMS.Model;
using LabMS.BLL;

namespace ExtendModule
{
    public class InstrumentAndConsumables: LabMS.Model.InstrumentAndConsumables
    {
        private string _totalprice = "";
        private string _cname = "";
        private string _labname = "";
        private string _totalnub = "";
        private string _totalusenub = "";

        public string TotalPrice
        {
            get
            {
                if (_totalprice.Equals(""))
                {
                    float tempf1 = 0.0f;
                    float tempf2 = 0.0f;
                    if (!float.TryParse(this.UnitPrice, out tempf2))
                    {
                        tempf2 = 0.0f;
                    }
                    if (!float.TryParse(this.Quantity.ToString(), out tempf1))
                    {
                        tempf1 = 0.0f;
                    }
                    float total = tempf1 * tempf2;
                    _totalprice = total.ToString();
                    return _totalprice;
                }
                else
                {
                    return _totalprice;
                }
            }
        }

        public string CName
        {
            get
            {
                if (_cname.Equals(""))
                {
                    List<LabMS.Model.Dictionary>listdic = new List<LabMS.Model.Dictionary>();
                    LabMS.BLL.Dictionary bdic
                        = new LabMS.BLL.Dictionary();
                    listdic = bdic.GetModelList(" Code = '" + this.ClassNumber + "'");
                    if (listdic.Count > 0)
                    {
                        _cname = listdic[0].Name;
                    }
                    else
                    {
                        _cname = "*";
                    }

                }
                return _cname;
            }
        }

        public string LabName
        {
            get
            {
                if (_labname.Equals(""))
                {
                    List<LabMS.Model.Location> listlab = new List<LabMS.Model.Location>();
                    LabMS.BLL.Location blab
                        = new LabMS.BLL.Location();
                    if (this.StockLocation.Equals(""))
                    {
                        _labname = "*";
                    }
                    else
                    {
                        try
                        {
                            listlab = blab.GetModelList(" ID = " + this.StockLocation);
                        }
                        catch
                        {
                            _labname = "*";
                        }
                        if (listlab.Count > 0)
                        {
                            _labname = listlab[0].Location_Name;
                        }
                        else
                        {
                            _labname = "*";
                        }
                    }

                }
                return _labname;
            }
        }

        public string TotalNub
        {
            get { return _totalnub; }
            set { _totalnub = value; }
        }

        public string TotalUseNub
        {
            get { return _totalusenub; }
            set { _totalusenub = value; }
        }

    }
}
